class Solution(object):
    def mostPoints(self, questions):
        n = len(questions)
        ans = [0] * n
        max_val = 0
        for i in range(n):
            if i > 0:
                ans[i] = max(ans[i - 1], ans[i])
            if i + questions[i][1] + 1 < n:
                ans[i + questions[i][1] + 1] = max(ans[i + questions[i][1] + 1], ans[i] + questions[i][0])
            else:
                max_val = max(max_val, ans[i] + questions[i][0])
        return max_val